<template>
  <div class="newEditVersion">
    <a-tabs v-model:activeKey="activeKey">
      <a-tab-pane key="version" tab="ECU版本信息" v-if="ecuVersionPermission">
        <new-edit-version ref="newEditVersion" :recordData="recordData" :fixedEcu="fixedEcu"/>
      </a-tab-pane>
      <a-tab-pane key="package" :tab="$t('fileConfiguration')" :disabled="!recordData.id" v-if="packagePermission">
        <file-configuration :recordData="recordData" v-if="recordData.id"/>
      </a-tab-pane>
    </a-tabs>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import { softwarePerms } from '@/config/permission/index'
import { minxinDrawerUse } from '@/utils/mixin'

export default {
  name: 'VersionTabs',
  mixins: [minxinDrawerUse],
  components: {
    FileConfiguration : () => import('./FileConfiguration.vue'),
    NewEditVersion : () => import('./NewEditVersion.vue'),
  },
  props: {
    type: {
      type: String,
      default: () => {
        return 'version'
      }
    },
    recordData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    fixedEcu: {
      type: Object,
      default: () => {
        return null
      }
    },
    // allEcuList: {
    //   type: [Array, Object],
    //   default: () => {
    //     return []
    //   }
    // }
  },
  computed: {
    ...mapState({
      instantUpdateTime: (state) => state.app.instantUpdateTime
    }),
    ecuVersionPermission(){
      if (this.recordData.id) {
        return this.$hasPermission([softwarePerms.partsSoftware.edit])
      }
      return this.$hasPermission([softwarePerms.partsSoftware.add])
    },
    packagePermission(){
      return this.$hasPermission([softwarePerms.partsSoftware.packageConfig, softwarePerms.partsSoftware.view])
    },
    activeKey :{
      get(){
        let real = this.selectedTab;
        if(!real){
          real = this.type;
        }
        this.setShowFooter(real == 'version');
        return real;
      },
      set(val){
        this.selectedTab=val;
        return val;
      }
    },
  },
  data () {
    return {
      selectedTab: null,
    }
  },
  mounted () {
  },
  methods: {
    getFormData() {
      return this.$refs.newEditVersion.getFormData();
    }
  },
  /**
   *
   */
  watch: {

    /**
     *
     * @param val
     */
    'recordData.id'(val) {
      if (!val) {
        this.activeKey = 'version';
      }
    },
    drawerMainOpened(val) {
      this.selectedTab = null;
    }
  }
}
</script>
<style lang="less">
  .app-drawer-main-content .newEditVersion {
    height: 100%;
    .ant-tabs {
      height: 100%;
      .ant-tabs-bar{
        padding-left: 40px;
      }
      .ant-tabs-content {
        /*overflow-y: auto;*/
        /*overflow-x: hidden;*/
        height: ~"calc(100% - 63px)";
        .ant-tabs-tabpane-active{
          overflow-y: auto;
        }
      }
    }
  }
</style>
<style lang="less" scoped>
  .iconWrap {
    width: 32px;
    height: 32px;
    text-align: center;
    border: 1px solid rgb(242, 242, 242);
    border-radius: @border-radius-base;
    float: right;
    margin-top: 4px;
    line-height: 32px;
    cursor: pointer;
  }

</style>
